package matrixcollision;

/**
 *
 * @author Verwalter
 */
public class FastMatrix {
    //here we store our values
    long[] rows;        //each row has at least 63 availible bits 64 if also use the signum
    int dim_x = 0;
    int dim_y = 0;

    //Constructor for Zero Matrix
    FastMatrix(int dim_x, int dim_y)
    {
        if(dim_x * dim_y == 0) System.exit(100);
        this.rows = new long[dim_y];
        this.dim_x = dim_x;
        this.dim_y = dim_y;
    }
    //Constructor for Homogene Matrix
    FastMatrix(int dim_x, int dim_y, boolean val)
    {
        this.rows = new long[dim_y];
        this.dim_x = dim_x;
        this.dim_y = dim_y;

        for(int i = 0; i < dim_y; i++)
        {
            for(int j = 0; j < dim_x; j++)
            {
                this.rows[i] = (this.rows[i] << 1) | ((val) ? 1:0);
            }
        }
    }

    public void print()
    {
        for(int i = 0; i < dim_y; i++)
        {
            System.out.println(Long.toString(this.rows[i], 2));
        }
    }
/*
    public void print(char true_symbol, char false_symbol)
    {
        for(int i = 0; i < this.dim_x; i++)
        {
            for(int j = 0; j < this.dim_y; j++)
            {
                if(this.values[i][j])
                {
                    System.out.print(true_symbol + " ");
                }
                else
                {
                    System.out.print(false_symbol + " ");
                }
            }
            System.out.println();
        }
    }

    public void invertValues()
    {
        for(int i = 0; i < this.dim_x; i++)
        {
            for(int j = 0; j < this.dim_y; j++)
            {
                this.values[i][j] = !this.values[i][j];
            }
        }
    }

    public FastMatrix or_with(Matrix other)
    {
        // TODO Check for size
        FastMatrix result = new FastMatrix(this.dim_x, this.dim_y);

        for(int i = 0; i < this.dim_x; i++)
        {
            for(int j = 0; j < this.dim_y; j++)
            {
                result.values[i][j] = this.values[i][j] || other.values[i][j];
            }
        }

        return result;
    }

    public FastMatrix xor_with(Matrix other)
    {
        // TODO Check for size
        FastMatrix result = new FastMatrix(this.dim_x, this.dim_y);

        for(int i = 0; i < this.dim_x; i++)
        {
            for(int j = 0; j < this.dim_y; j++)
            {
                result.values[i][j] = this.values[i][j] ^ other.values[i][j];
            }
        }

        return result;
    }
    */
    public FastMatrix and_with(FastMatrix other)
    {
        // TODO Check for size
        FastMatrix result = new FastMatrix(this.dim_x, this.dim_y);

        for(int i = 0; i < this.dim_y; i++)
        {
            result.rows[i] = this.rows[i] & other.rows[i];
        }

        return result;
    }
}
